<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;


class ShareSendGoods extends Base
{
    protected $table = 'share_send_goods';

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
    }

    public function createSendGoodsLog($data)
    {
        $data['created_at'] = $data['updated_at'] = date_ymd();
        $res = DB::table($this->table)->insertGetId($data);
        if(!$res)
           return false;
        return $res;
    }

    /*
         * 赠送记录
         * @param [$user_id]   用户id
         * @param [$send_type]   赠送类型
         * */
    public function sendUserLog($user_id,$goods_type = [],$send_type = 1)
    {
        if(empty($goods_type))
            $goods_type = ['0','1','2','3'];
        $db = DB::table($this->table)
            ->where(['user_id'=>$user_id,'send_type'=>$send_type])
            ->whereIn('goods_type', $goods_type)
            ->get();

        if(empty(self::objToArray($db)))
            return false;//无记录
        return true;//有记录
    }
}